using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Product : System.Web.UI.UserControl
{
    processProduct pProduct;
    PagedDataSource pDataSource;
    protected void Page_Load(object sender, EventArgs e)
    {
        string ProductTypeID = Request.QueryString["ProductTypeID"];
        string ProductID = Request.QueryString["ProductID"];   
        pProduct = new processProduct();
        //dtlProduct.DataSource = pProduct.getProductByType(ProductTypeID).Tables[0];
        //dtlProduct.DataKeyField = "ProductTypeID";
        //dtlProduct.DataBind();

        //Pagging
        pDataSource = new PagedDataSource();        
        pDataSource.DataSource = pProduct.getProductByType(ProductTypeID).DefaultView;
        pDataSource.AllowPaging = true;
        pDataSource.PageSize = 8;
        pDataSource.CurrentPageIndex = 0;
        dtlProduct.DataSource = pDataSource;
        //dtlProduct.DataKeyField = "ProductTypeID";
        dtlProduct.DataBind();
        string pages = null;
        for (int i = 0; i < pDataSource.PageCount; i++)
        {
            pages = pages + "<a href='index.aspx?subpara=product&ProductTypeID="+ProductTypeID+"&page=" + i + "'>" + (i + 1) + "</a>||";
        }
        lblPage.Text = pages;
        if (Request["page"] != null)
        {
            int page = Int32.Parse(Request["page"]);
            pDataSource.CurrentPageIndex = page;
            dtlProduct.DataSource = pDataSource;
            dtlProduct.DataBind();
            //Label1.Text = page.ToString();
        }     
                
    }
    protected void dtlProduct_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        Label lblProductName = (Label)e.Item.FindControl("lblProductName");
        Label lblProductPrice = (Label)e.Item.FindControl("lblProductPrice");
        Label lblProductQuantity = (Label)e.Item.FindControl("lblProductQuantity");        
        ImageButton ibtProductImage = (ImageButton)e.Item.FindControl("ibtProductImage");
        HyperLink hplProductDetail = (HyperLink)e.Item.FindControl("hplProductDetail");        
        DataRowView row = (DataRowView)e.Item.DataItem;
        lblProductName.Text = row["ProductName"].ToString();
        lblProductPrice.Text = row["ProductPrice"].ToString();
        lblProductQuantity.Text = row["ProductQuantity"].ToString();                
        ibtProductImage.ImageUrl = "Images/" + row["ProductImage"].ToString();
      //  ibtProductImage.PostBackUrl = "index.aspx?subpara=productdetail&ProductID=" + ((DataRowView)e.Item.DataItem)["ProductID"].ToString();        
        hplProductDetail.NavigateUrl = "index.aspx?subpara=productdetail&ProductID=" + ((DataRowView)e.Item.DataItem)["ProductID"].ToString();       

    }
   
}
